﻿using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using SmartCity.Shared;
using Volo.Abp;
using Volo.Abp.AspNetCore.Mvc;

namespace CommonManagement
{
    /// <summary>
    /// 评论控制器
    /// </summary>
    [RemoteService]
    [Area("commonManagement")]
    [Route("api/commonManagement/comments")]
    public class CommentController : AbpController, ICommentAppService
    {
        private readonly ICommentAppService _commentAppService;

        public CommentController(
            ICommentAppService commentAppService)
        {
            _commentAppService = commentAppService;
        }

        // 1.5.2 获取新闻评论列表
        [HttpGet]
        [Route("list")]
        public Task<ListResponse<CommentDto>> PagedListAsync(PagedListRequest request, 
            int newsId, int? userId = null, DateTime? commentDate = null)
        {
            return _commentAppService.PagedListAsync(request, newsId, userId, commentDate);
        }

        // 1.5.3 获取新闻评论详细信息
        [HttpGet]
        [Route("{id:int}")]
        public Task<ResultResponse<CommentDto>> GetAsync(int id)
        {
            return _commentAppService.GetAsync(id);
        }

        // 1.5.7 发表新闻评论
        [Authorize]
        [HttpPost]
        [Route("")]
        public Task<ActionResponse> CreateAsync(CommentCreateDto input)
        {
            return _commentAppService.CreateAsync(input);
        }

        // 1.5.8 评论点赞
        [Authorize]
        [HttpPut]
        [Route("like/{id:int}")]
        public Task<ActionResponse> LikeAsync(int id)
        {
            return _commentAppService.LikeAsync(id);
        }
    }
}